/* Ejercicio 4.25
   ejer4_25.c */
#include <stdio.h>

/* funcion main, el programa inicia aca */
int main( void )
{
    int n, x;
    int position;
    int digit;

    printf( "Base 10\tBase 2\t\tBase 8\tBase 16\n" );

    for ( x = 1; x <= 256; x++ ) {
        printf( "%d\t", x );
        /* Base 2 */
        n = x;
        position = 1;

        while ( position <= n ) {
            position *= 2;
        }

        position /= 2;

        while ( position != 0 )
        {
            digit = n / position;
            printf( "%c", digit + '0' );
            n %= position;
            position /= 2;
        }

        if ( x <= 127 ) {
            printf( "\t" );
        }

        /* Base 8 */
        n = x;
        position = 1;

        while ( position <= n ) {
            position *= 8;
        }

        position /= 8;printf( "\t" );

        while ( position != 0 )
        {
            digit = n / position;
            printf( "%c", digit + '0' );
            n %= position;
            position /= 8;
        }

        printf( "\t" );

        /* Base 16 */
        n = x;
        position = 1;

        while ( position <= n ) {
            position *= 16;
        }

        position /= 16;

        while ( position != 0 )
        {
            digit = n / position;
            printf( "%c", ( digit < 10 ) ? digit + '0' : digit - 10 + 'A' );
            n %= position;
            position /= 16;
        }

        printf( "\n" );
    }
	return 0;
} /* fin de la funcion main */
